<template>
	<view>
		<view class="table">
			<zy-table :headList="headList" :dataList="dataList" border></zy-table>
		</view>
		<view class="btn">
			<zy-button @click="submitBtn" :disabled="disabled" class="" type="primary">{{$t("public.sure")}}</zy-button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				headList: [{
						name: this.$t('homepage.QualityControl.defectName'),
						key: 'name',
					},
					{
						name: this.$t('public.num'),
						key: 'num',
						edit: true,
						type: 'number',
						sum: true
					}
				], //疵点录入表格表头
				dataList: [], //疵点录入表格数据
				disabled: true, //底部按钮数据不变时禁用
				info: {},
			}
		},
		onLoad: function(option) {
			setTimeout(() => {
				this.info = JSON.parse(option.defectData)
				this.dataList = this.info.defect
			}, 500)
		},
		watch: {
			// 监听表格数据是否改变
			dataList: {
				handler(n, o) {
					let obj = n.find((v) => (v.num > 0))
					if (obj) {
						this.disabled = false
					} else {
						this.disabled = true
					}
				},
				deep: true
			},
		},
		methods: {
			//提交事件
			submitBtn() {
				let data = {}
				this.$set(this.info, "defect", this.dataList)
				uni.$emit('updateData', this.info)
				uni.navigateBack({
					delta: 1
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.table {
		margin-bottom: 50px;
	}

	.btn {
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 999;
	}
</style>